package com.javasm.boot.oauth2.controller;

import com.javasm.boot.oauth2.entity.MyAuthentication;
import com.javasm.boot.oauth2.entity.Perm;
import com.javasm.boot.oauth2.entity.Response;
import com.javasm.boot.oauth2.entity.vo.UserInfoVO;
import com.javasm.boot.oauth2.entity.vo.UserVO;
import com.javasm.boot.oauth2.service.IUserService;
import com.javasm.boot.oauth2.utils.WebUtils;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户信息 前端控制器
 * </p>
 *
 * @author modebing
 * @since 2022-12-13
 */
@RestController
@RequestMapping("/user")
@AllArgsConstructor
public class UserController {

    private IUserService userService;
    private WebUtils webUtils;

    @GetMapping("/query")
    @Perm
    public void query() {
        Response resp = new Response().code(HttpStatus.OK).msg("查询成功");
        webUtils.renderString(resp);
    }


    @DeleteMapping("/delete")
    @Perm(MyAuthentication.DELETE)
    public void delete() {
        Response resp = new Response().code(HttpStatus.OK).msg("删除成功");
        webUtils.renderString(resp);
    }

    @PostMapping("insertUserInfo")
    public void insert(UserInfoVO userVO){
        Response resp = userService.insertUserInfo(userVO);
        webUtils.renderString(resp);
    }


    /**
     * 自定义登录 获取token
     * 内部系统登录，非三方登录,以form表单的方式提交
     *
     * @return
     */
    @PostMapping("/innerLogin")
    public void innerLogin(UserVO userVO) {
        webUtils.renderString(userService.innerLogin(userVO));
    }
}
